from flask import Blueprint, request, current_app, send_file
import os
from utilsapp.mysql_con import db_connect, db_delete, db_insert, db_list, db_fetchone, db_operation, db_table_pagelist, \
    db_update, get_sensor_new_table
from utilsapp import utils
import time
import pandas as pd
from datetime import datetime
from utilsapp.common import parsing_data_id, assign_value
import math
import asyncio

eigenvalue = Blueprint('sys_wave', __name__)
tableName = 'sys_wave'
# 指标类型

@eigenvalue.route("/getlist", methods=['POST'])
def table_list():
    if 'page' in request.json.keys() and 'size' in request.json.keys():
        page = request.json['page']
        size = request.json['size']
    else:
        page = 1
        size = 999
    j = db_table_pagelist(tableName, page, '', size)
    return j


@eigenvalue.route("/add", methods=["POST"])
def eigenvalue_add():
    return db_insert(tableName, request.json)


@eigenvalue.route('/delete', methods=['POST'])
def eigenvalue_delete():
    id = request.json['id']
    return db_delete(tableName, f'WHERE id=%s', {'id': id})


@eigenvalue.route('/edit', methods=['post'])
def eigenvalue_edit():
    id = request.json['id']
    keys_not_add = ['id']
    addModel = {key: request.json[key]
                for key in request.json if key not in keys_not_add}
    return db_update(tableName, addModel, f'WHERE id=%s', {"id": id})


